﻿using System;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.UI.WebControls;

namespace Solution
{
    public abstract class BaseApiController : ApiController
    {
        #region 公共方法

        protected StandardResult Try(Action action,string msg="ok")
        {
            var result = new StandardResult();
            result.Try(action);
            result.Message = msg;
            return result;
        }

        protected StandardResult<T> Try<T>(Func<T> action, string msg = "ok")
        {
            var result = new StandardResult<T>();
            result.Try(() =>
            {
                result.Value = action();
            });
            result.Message = msg;
            return result;
        }

        #endregion 公共方法

        #region 保护方法

        /// <summary>
        /// 当前登录用的ID
        /// </summary>
        /// <returns></returns>
        protected Guid GetUserId()
        {
            return Guid.Parse(FormTicketHelper.GetUserId());
        }

        #endregion 保护方法
    }
}